$(function() {
    var key = getCookie('key');
    if (!key) {
        window.location.href = WapSiteUrl + '/tmpl/member/login.html';
    }

    $.ajax({
        type:"get",
        url:ApiUrl+"/index.php?act=member_index&op=card_info",
        data:{key:key},
        dataType:"json",
        success:function(res){
               if (res){
                    var html = template.render("card_info_tpl",res);
                    $("#card_info").html(html);
               }
        }
    })

    $(".btn").on('click', function () {
        // 验证表单
        var name = $('#name').val();
        var card_num = $('#card_num').val();
        var bank_account = $('#bank_account').val();
        var branch_account = $('#branch_account').val();
        var tel = $('#tel').val();
        var isedit = $("#isedit").val();

        if(name==''||bank_account==''||branch_account==''||card_num==''||tel==''){
               creatLayout('卡号信息不能为空');
               return;
        }

        // 验证银行卡格式是否规范
        var CardReg =  /^\d{16}|\d{19}$/;
        if (!CardReg.test(card_num)){
               creatLayout('银行卡格式错误');
               return;
        }

        var telReg = /^1[3|4|5|7|8][0-9]{9}$/;
        if (!telReg.test(tel)){
            creatLayout("请填写正确的手机号");
            return;
        }

        var data = {key:key,name:name,card_num:card_num,bank_account:bank_account,branch_account:branch_account,tel:tel,isedit:isedit};
        $.ajax({
            type:"POST",
            url:ApiUrl+"/index.php?act=member_index&op=edit_card",
            data:data,
            dataType:"json",
            success:function(res){
                 if(res['code']==200){
                       creatLayout("银行卡修改成功");
                 }else{
                       creatLayout("银行卡修改失败");
                 }
            }
        })
    })




})